package com.yantong.controller;

import com.yantong.result.ResultVo;
import com.yantong.utils.PageUtils;
import com.yantong.pojo.Video;
import com.yantong.service.VideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 小程序视频接口
 * @Auther: chenhu
 * @Date: 2020/08/08
 * @Description:
 */
@Controller
@RequestMapping("/wxapi/video")
public class ApiVideoController extends BaseController {
    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "视频列表数据")
    @ResponseBody
    @GetMapping("/list")
    public ResultVo list(String title, Long centre_id, String video_id, Integer offset, Integer limit) {
        PageUtils<Video> videos = videoService.videoList(title,centre_id,video_id,offset,limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("data", videos);
        return resultVo;

    }

    @ApiOperation(value = "视频详情")
    @ResponseBody
    @GetMapping("/detail")
    public ResultVo detail(String id) {
        Long vid = Long.parseLong(id);
        Video video = videoService.getVideoPrimaryKey(vid);
        //阅读+1
        Video v = new Video();
        v.setId(vid);
        v.setType("reads");
        if (videoService.updateVideoAddOne(v) < 1) {
            return ResultVo.error();
        }
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", video);
        return resultVo;
    }

    @ApiOperation(value = "视频点赞")
    @ResponseBody
    @GetMapping("/likes")
    public ResultVo likes(String id) {
        Long vid = Long.parseLong(id);
        Video video = new Video();
        video.setId(vid);
        video.setType("likes");
        //点赞+1
        if (videoService.updateVideoAddOne(video) < 1) {
            return ResultVo.error();
        }
        ResultVo resultVo = new ResultVo();
        return resultVo;
    }
}
